# -*- coding: utf-8 -*-
'''
Created on 13/ott/2009

@author: sax
'''
from django import template

register = template.Library()
                            
def xsubmit_row(context):
    opts = context['opts']
    change = context['change']
    is_popup = context['is_popup']
    save_as = context['save_as']
    editable = not context.get('read_only',False)
    return {
        'onclick_attrib': (opts.get_ordered_objects() and change
                            and 'onclick="submitOrderForm();"' or ''),
        'show_delete_link': editable and (not is_popup and context['has_delete_permission']
                              and (change or context['show_delete'])),
        'show_save_as_new': editable and  not is_popup and change and save_as,
        'show_save_and_add_another': editable and  context['has_add_permission'] and 
                            not is_popup and (not save_as or context['add']),
        'show_save_and_continue': editable and not is_popup and context['has_change_permission'],
        'is_popup': is_popup,
        'show_save': editable and context.get('show_save', True)
    }
xsubmit_row = register.inclusion_tag('xadmin/submit_line.html', takes_context=True)(xsubmit_row)
